﻿//var dunDate = dataFormat(new Date(), "yyyy-MM-dd");
//var SelectTypeDUNCOUNT = "";
var weightForDistrictCLCInfoList;
var dateDistrictCLCInfoList = new Ext.form.Label({ width: 300 });
var dunDistrictCLCInfoList = new Ext.form.Label({ width: 300 });

function clcWeightForDistrict() {
    if (Ext.getCmp('DistrictCLCwindow') == null) {
        var PanelDistrictCLCInfoList = new Ext.Panel({

            region: 'center',
            
//            title: '处理厂按区统计',
            anchor: '100% 100%',
            closable: true,
            autoScroll: true,
            containerScroll: true,
            //margins: '0 0 0 5',
            border: false,
            iconCls: 'nav',
            items: [createConditionsForDistrictCLC(), {
                layout: 'fit',
                items: [createItemsForDistrictCLC()]
            }]
        });
        var window = new Ext.Window({
            title: "处理厂按区统计",
            id: 'DistrictCLCwindow',
            layout: 'fit',       //弹出窗口内布局会充满整个窗口;
            width: 600,          //设置窗口大小;
            height: 400,
            items: PanelDistrictCLCInfoList         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
        });
        window.show();
    }

    updataDataForDistrictCLC(dataFormat(new Date(), "yyyy-MM-dd"), "");
}


function updataDataForDistrictCLC(dataPara, typePara) {
    weightForDistrictCLCInfoList.removeAll();
    weightForDistrictCLCInfoList.load({
        params: { dateString: dataPara, type: "处理厂", typeLJ: typePara, op: 'GetDistrictWeightAllBh' }
                    , callback: function (records, options, success) {
                        if (success) {
                            dateDistrictCLCInfoList.setText(records[0].get("dateAll"));
                            dunDistrictCLCInfoList.setText(records[0].get("weightAll"));

                        }
                    }
    });
    
}

function createConditionsForDistrictCLC() {
    return new Ext.Panel({
//        labelAlign: 'top',
        frame: true,
        bodyStyle: 'padding:0px 0px 0',
        items: [
                                {
                                    //                                    columnWidth: .5,
                                    height: 30,
                                    layout: { type: 'hbox' },
                                    items: [
                                    {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "今日",
                                        id: "date1",
                                        checked: true

                                    }, {
                                        width: 100,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "昨日",
                                        id: "date2"

                                    }, {
                                        width: 100,
                                        xtype: "label"
                                    },
                                    {
                                        xtype: "label",
                                        width: 80,
                                        text: '处理厂类型：'
                                    }, initTYPELJ(1)
                                    ]
                                },

                                {
                                    //                                    columnWidth: .5,
                                    height: 30,
                                    layout: { type: 'hbox' },
                                    items: [
                                    {
                                        width: 70,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "按日期",
                                        id: "date3"

                                    }, {
                                        width: 150,
                                        xtype: 'datefield',
                                        format: 'Y-m-d',
                                        id: "dateSearch"
                                    },{
                                        width: 80,
                                        xtype: "label"
                                    }, dunDistrictCLCInfoList
                                    ]
                                }, {
                                    //                                    columnWidth: .5,
                                    height: 30,
                                    layout: { type: 'hbox' },
                                    items: [
                                    {
                                        width: 70,
                                        xtype: "radio",
                                        name: "sex",
                                        boxLabel: "按月份",
                                        id: "date4"

                                    }, {
                                        xtype: 'datefield',
                                        width: 150,
                                        format: 'Y-m',
                                        id: "monthSearch"
                                    }, {
                                        width: 80,
                                        xtype: "label"
                                    },
                                    dateDistrictCLCInfoList]
                                }],
        buttonAlign: 'center',
        buttons: [{
            text: "查询",
            name: "button",
            handler: function () {
                var dunDate;
                if (Ext.getCmp('date1').checked) {
                    var yesterday = new Date();
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
                if (Ext.getCmp('date2').checked) {
                    var yesterday = new Date();
                    yesterday.setTime(yesterday.getTime() - 3600 * 1000 * 24);
                    dunDate = dataFormat(yesterday, "yyyy-MM-dd");
                }
                if (Ext.getCmp('date3').checked) {
                    if (Ext.getCmp('dateSearch').getValue() == "") {
                        Ext.MessageBox.alert("提示", "请选择日期");
                    } else {
                        dunDate = dataFormat(Ext.getCmp('dateSearch').getValue(), "yyyy-MM-dd");
                    }
                }
                if (Ext.getCmp('date4').checked) {
                    if (Ext.getCmp('monthSearch').getValue() == "") {
                        Ext.MessageBox.alert("提示", "请选择月份");
                    } else {
                        dunDate = dataFormat(Ext.getCmp('monthSearch').getValue(), "yyyy-MM"); ;
                    }

                }
                updataDataForDistrictCLC(dunDate, Ext.get('cmbTypeLJ').getValue(), "处理厂");
            }
        }]
    });
}

//function getVehicleWeight(clientName, date, type, nameFactory, functionName) {
//    var panel = new Ext.Panel({
//        //        title: ' My Panel ', // 标题
////        collapsible: true, // 右上角上的那个收缩按钮，设为false则不显示
////        renderTo: 'WeightVehicleInfoList', // 这个panel显示在html中id为container的层中
//        anchor: '100% 100%',
//        html: '<iframe src="./html/WeightVehicleInfoList.html?clientName=' + clientName + '&date=' + date + '&nameFactory=' + name + '&type=' + type + '&functionName=' + functionName + ' "width="100%" height="100%"></iframe>' //panel 主体中的内容，可以执行html代码

//    });
////    var panel = new Ext.TabPanel({

////        fullscreen: true,
////        activeTab: 0,
////        defaults: {
////            styleHtmlContent: true
////        },
////        items: [
////            {
////                title: '全部',
////                html: '<iframe src="./html/WeightVehicle.aspx?clientName=' + clientName + '&dateString=' + document.getElementById("ljSearchData").value + '&name=' + name + ' "width="100%" height="100%"></iframe>'
////            }
////            ]
////    });

//    var window = new Ext.Window({
//        title: '车辆详情',
//        layout: 'fit',       //弹出窗口内布局会充满整个窗口;
//        width: 800,          //设置窗口大小;
//        height: 500,
//        items: panel         //默认会生成Ext.Panel类型的对象;并且随窗口大小改变而改变;
//    });
//    window.show();
//}
//function rMenu2Fn(bb) {
//    alert(bb);
//}
function createItemsForDistrictCLC() {
//    var sm = new Ext.grid.CheckboxSelectionModel(); 
    // 列
    var cm = new Ext.grid.ColumnModel([
        { header: '地区', dataIndex: 'name', sortable: true, width: 60 },
    //        { header: '报警类型', dataIndex: 'Alarm_Type', sortable: true, renderer: GetAlarmTypeString, width: 64 },
        {header: '吨数', dataIndex: 'dunCount', sortable: true, width: 58 },
        {
            header: "操作",
            width: 100,
            dataIndex: 'operation',
            align: 'center',
            renderer: function (value, cellmeta, record, rowIndex, columnIndex, store) {
                var clientName = record.data["name"];
                var date = record.data["dateAll"];
                var stringbtn = "<button type='button' onclick='getFactoryWeightByDistrictJS(\"" + clientName + "\",\"" + date + "\",\"处理厂\",\"\")'>处理厂详情</button>"
                //                    + "<button type='button' onclick='getVehicleWeight(\"" + clientName + "\",\"" + date + "\",\"处理厂\",\"\",\"GetVehicleWeightByDistrict\")'>车辆详情</button>";
+ "&nbsp;&nbsp;<button type='button' onclick='getVehicleWeightByDistrictJS(\"" + clientName + "\",\"" + date + "\",\"处理厂\",\"\")'>车辆详情</button>";
                return stringbtn;
            }
        }]);

    // 数据源
        weightForDistrictCLCInfoList = new Ext.data.Store({
        url: "../Json/JsonGetWeightInfoList.ashx",
        reader: new Ext.data.JsonReader(
                { root: 'data' },
                Ext.data.Record.create([{ name: 'name' }, { name: 'dunCount' }, { name: 'dateAll' }, { name: 'weightAll'}])
            )
    });

    return new Ext.grid.GridPanel({
        anchor: '100%',
        layout: 'fit',
        enableHdMenu: false,
        autoScroll: true,
        containerScroll: true,
        autoHeight: true,
        //title: '报警列表',
        loadMask: { msg: '正在加载数据，请稍侯……' },
        //el: 'grid',
        store: weightForDistrictCLCInfoList,
        cm: cm,
        //bbar: bbar,
        bodyStyle: 'height:100%',
        viewConfig: {
            forceFit: true
        }
    });

}
